import pymysql
import requests


# 登录
my = {"username":"19515542478","password":"123456"}
a = requests.post("http://192.168.124.121:8080/login",data=my)
# print(a.json())
# 提取token
rdata = a.json()
t = rdata["Admin-Token"]
# t=rdata.get("Admin-Token")
token = {"Admin-Token": t}


# 工作台信息统计
a = requests.post("http://192.168.124.121:8080/OaBackLog/num",headers=token)
# print(a.json())
# 工作台任务列表
a = requests.post("http://192.168.124.121:8080/OaRecord/queryTask",headers=token)
# print(a.json())
# 工作台当月日
a = requests.post("http://192.168.124.121:8080/OaRecord/queryEvent",data="month=2023-09",headers=token)
# print(a.json())
# 工作台当日日
a = requests.post("http://192.168.124.121:8080/OaRecord/queryEventByDay",data="day=2023-09-26",headers=token)
# print(a.json())
# 工作台全部
z = {"type":"0","page":"1","limit":"15"}
a = requests.post("http://192.168.124.121:8080/OaRecord/getOaRecordPageList",data=z,headers=token)
# print(a.json())



# 文件上传
msgdata = {"type":"img"}
f1 = open(r"C:\Users\立哲\Pictures\Saved Pictures\01.jpg","rb")
msgfile = {"file":("01.jpg",f1,"image/jpg")}
a = requests.request("post","http://192.168.124.121:8080/file/upload",data=msgdata,files=msgfile,headers=token)
# print(a.json())

# 获取batchId
rrdata = a.json()
t1 = rrdata["batchId"]
batchId = {"batchId":t1}

# 新增日志
add = {
   "categoryId": "1",
   "content": "今日工作内容~",
   "tomorrow": "明日工作计划~",
   "question": "今日遇到的问题~",
   "batchId": batchId,
   "sendUserIds": "2,3",
   "sendDeptIds": "",
   "customerIds": "",
   "contactsIds": "",
   "businessIds": "",
   "contractIds": ""
   }
a = requests.post("http://192.168.124.121:8080/OaLog/addOrUpdate",json=add,headers=token)
# print(a.json())
# 修改日志
x = {
   "logId":"1",
   "categoryId": "1",
   "content": "这里是今日内容的修改",
   "tomorrow": "这里明日工作计划的修改",
   "question": "这里是今日遇到的问题的修改",
   "batchId": "",
   "sendUserIds": "2，3",
   "sendDeptIds": "",
   "customerIds": "",
   "contactsIds": "",
   "businessIds": "",
   "contractIds": ""
}
xg = requests.post("http://192.168.124.121:8080/OaLog/addOrUpdate",headers=token,json=x)
# print(xg.json())


# 查询日志
z = {"page":1,"limit":5,"by":"1"}
a = requests.post("http://192.168.124.121:8080/OaLog/queryList",data=z,headers=token)
print(a.json())
# 删除日志


# 连接数据库
databases = pymysql.connect(user='root', password='123456', host='192.168.124.121', database='crm9')

# 创建游标对象
cursor = databases.cursor()

# 编写sql语句并执行
cursor.execute("SELECT log_id from 72crm_oa_log where create_user_id =9;")
databases.commit()

#所有行查看
dataaa=cursor.fetchall()
print(dataaa)

# 删除留言
for i in dataaa:
   logg = {"logId": i[0]}
   requests.post("http://192.168.124.121:8080/OaLog/deleteById", data = logg, headers=token)


sql=cursor.execute("SELECT log_id from 72crm_oa_log where create_user_id =9;")
dataaa = cursor.fetchall()
print(dataaa)

if sql == 0:
   print("删除成功")

